<template>
  <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
  <div id="mychart" style="width: 100%; height: 200px"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  name: "PillarChart",
  props: {
    typeChart: {
      type: String,
      default: "bar",
    },
  },
  data() {
    return {};
  },
  mounted() {
    this.initChart();
    // this.initWebSocket();
  },
  methods: {
    initChart() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("mychart"));

      var option = {
        title: {
          text: "设备能耗检测",
          textStyle:{
             lineHeight: 50,
             color:"#fff",
          }
        },
        xAxis: {
          type: "category",
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: [820, 932, 901, 934, 1290, 1330, 1320],
            type: "bar",
            smooth: true,
          },
        ],
      };

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    },
    initWebSocket() {
      var ws = new WebSocket("ws://127.0.0.1:8090");

      ws.onopen = function () {
        alert("websocket");
      };
      (ws.onerror = function () {
        alert("出现错误");
      }),
        (ws.onmessage = (msg) => {
          console.log(msg);
        });
    },
  },
};
</script>

<style lang="scss" scoped></style>
